
package p2a;


import java.awt.*;
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

public class MainApplicationPanel extends JPanel {
    
  DefaultTableModel rules_table_model = new DefaultTableModel() {

    @Override
    public boolean isCellEditable(int row, int column) {
       //all cells false
       return false;
    }
};
  DefaultTableModel testcases_table_model = new DefaultTableModel() {

    @Override
    public boolean isCellEditable(int row, int column) {
       //all cells false
       return false;
    }
    

};
  
  BorderLayout borderLayout1 = new BorderLayout();
  JToolBar tool_bar = new JToolBar();
  JButton tool_bar_b1 = new JButton();
  JSplitPane spli_pane = new JSplitPane();
  JPanel testcase_panel = new JPanel();
  JScrollPane scroll_pane2 = new JScrollPane();
  JScrollPane rule_analysis_scroll_pane = new JScrollPane();
  JTextArea rules_analysis_result = new JTextArea();
          
  JTable test_cases_table = new JTable(testcases_table_model){
      
          @Override
            public void tableChanged(TableModelEvent e) {
                super.tableChanged(e);
                repaint();
            }
 
        @Override
      public Component prepareRenderer (TableCellRenderer renderer, int index_row, int index_col){ 
 Component comp = super.prepareRenderer(renderer, index_row, index_col); 

 String test_result = (String) this.getValueAt(index_row, 9);
 if( test_result != null){ 
     if(test_result.equalsIgnoreCase("testing"))
 comp.setBackground(new Color(128,255,255)); 
     else   if(test_result.equalsIgnoreCase("passed"))
 comp.setBackground(new Color(128,255,128)); 
     else   if(test_result.equalsIgnoreCase("failed"))
 comp.setBackground(new Color(255,128,128)); 
 } 
 else
    comp.setBackground(Color.white);  
 
 if(isCellSelected(index_row, index_col)){ 
 comp.setBackground(Color.lightGray); 
 
 } 
 return comp; 
 };
  };
  JPanel rules_panel = new JPanel();
  JTable rules_table = new JTable(rules_table_model);
  JScrollPane scroll_pane1 = new JScrollPane();
  BorderLayout borderLayout2 = new BorderLayout();
  BorderLayout borderLayout3 = new BorderLayout();
  JPanel rules_buttons_panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  JButton rules_b1 = new JButton();
  JPanel testcases_buttons_panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  JButton testcases_b1 = new JButton();
  JComboBox testcase_types = new JComboBox();
  JComboBox network_device_tx = new JComboBox();
  JComboBox network_device_rx = new JComboBox();
  JButton testcases_run = new JButton("Run");
  JButton toolbar_tes_run = new JButton("",new ImageIcon("/resources/play.png"));

  public MainApplicationPanel() {
    try {
      init();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }
  void init() throws Exception {
    testcases_b1.setText("Generate test cases");
    this.setLayout(borderLayout1);
    tool_bar_b1.setText("1");
    spli_pane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    spli_pane.setDividerLocation(200);
    testcase_panel.setLayout(borderLayout2);
    rules_panel.setLayout(borderLayout3);
    rules_b1.setText("Analyse rules");
    this.add(tool_bar, BorderLayout.NORTH);
    tool_bar.add(tool_bar_b1, null);
    tool_bar.add(toolbar_tes_run, null);
    this.add(spli_pane, BorderLayout.CENTER);
    spli_pane.add(testcase_panel, JSplitPane.BOTTOM);
    testcase_panel.add(scroll_pane2, BorderLayout.CENTER);
    scroll_pane2.setViewportView(test_cases_table);
    JSplitPane rules_split_pane = new JSplitPane();
    rules_split_pane.add(scroll_pane1,JSplitPane.LEFT);
    rules_split_pane.add(rule_analysis_scroll_pane,JSplitPane.RIGHT);
    rules_split_pane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    rules_panel.add(rules_split_pane,  BorderLayout.CENTER);
    rules_panel.add(rules_buttons_panel, BorderLayout.NORTH);
    rules_split_pane.setDividerLocation(0.7);
    
    
    //rules_panel.add(rule_analysis_scroll_pane, BorderLayout.EAST);
    rules_analysis_result.setEditable(false);
       rule_analysis_scroll_pane.setViewportView(rules_analysis_result);
    
    rules_buttons_panel.add(rules_b1, FlowLayout.LEFT);
    //scroll_pane1.add(rules_table, null);
    scroll_pane1.setViewportView(rules_table);
    spli_pane.add(rules_panel, JSplitPane.TOP);
    testcase_panel.add(testcases_buttons_panel, BorderLayout.NORTH);
    
    testcases_buttons_panel.add(testcase_types);
    testcases_buttons_panel.add(testcases_b1);
    testcases_buttons_panel.add(new JLabel("TX"));
    testcases_buttons_panel.add(network_device_tx);
    testcases_buttons_panel.add(new JLabel("RX"));
    testcases_buttons_panel.add(network_device_rx);
    testcases_buttons_panel.add(testcases_run);
  }
}
